<%--
  Created by IntelliJ IDEA.
  User: 莫
  Date: 2018/1/10
  Time: 20:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>

    <link href="css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
<nav class="navbar navbar-default">
    <div class="navbar-header">
        <button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-exl-collapse"><i class="fa fa-bars"></i></button>
        <a class="navbar-brand" href="#">后台管理</a>
    </div>
    <div class="collapse navbar-collapse navbar-exl-collapse">
        <ul class="nav navbar-nav">
            <li class="active"><a href="#">新闻 <span class="sr-only">(current)</span></a></li>
            <li><a href="#">Link</a></li>
        </ul>
    </div>>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-2">
            <a href="NewsManage_Admin.jsp" class="list-group-item ">新闻管理</a>
            <a href="User_Admin.jsp" class="list-group-item active">用户管理</a>
        </div>
        <div class="col-sm-10">
            <%--<div class="panel panel-default">--%>
                <%--<div class="panel-heading">--%>
                    <%--搜索--%>
                <%--</div>--%>
                <%--<div class="panel-body">--%>
                    <%--<form role="form" class="form-inline" action="">--%>
                        <%--<div class="form-group">--%>
                            <%--<label for="name">名称</label>--%>
                            <%--<input type="text" class="form-control" id="name" placeholder="请输入名称">--%>
                        <%--</div>--%>
                        <%--<div class="form-group">--%>
                            <%--<button type="submit" class="btn btn-default">开始搜索</button>--%>
                        <%--</div>--%>
                    <%--</form>--%>
                <%--</div>--%>
            <%--</div>--%>
            <!--
                列表展示
            -->
            <div class="table-responsive">
                <table class="table table-striped " id="table">
                    <thead>
                    <tr>
                        <th>用户ID</th>
                        <th>用户名</th>
                        <th>账号</th>
                        <th>权限</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>

                    </tbody>
                </table>
            </div>
            <ul class="pagination" style="float: right;">
                <li><a href="#">&laquo;</a>
                </li>
                <li class="active"><a href="#">1</a>
                </li>
                <li class="disabled"><a href="#">2</a>
                </li>
                <li><a href="#">3</a>
                </li>
                <li><a href="#">4</a>
                </li>
                <li><a href="#">5</a>
                </li>
                <li><a href="#">&raquo;</a>
                </li>
            </ul>
        </div>
    </div>
</div>
<script src="js/jquery-2.1.1.min.js"></script>
<script>
    var xmlhttp;
    function getUrlParams(name)
    {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return r[2]; return "";
    }
    var name = getUrlParams("name");
    //获取cookie值

    window.onload = function () {
        xmlhttp=new XMLHttpRequest();
        xmlhttp.open("POST","UserTbHtml",false);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send("FN=1");

        var user = JSON.parse(xmlhttp.responseText);
        var UsersList = user.UsersList;
        // var name = getUrlParams("name");

        // Cookie接收
        // var CurUserName=getCookie("CurUserName");//另外一个页面用getCookie来获取值  
        // console.log(CurUserName);

        var table = document.getElementById("table");
        for (var i = 0;i<UsersList.length;i++)
        {
                var row = table.insertRow(table.rows.length);
                var ID = row.insertCell(0);
                ID.innerHTML = UsersList[i].UserID;
                var Head = row.insertCell(1);
                Head.innerHTML = UsersList[i].UserName;
                var Name = row.insertCell(2);
                Name.innerHTML = UsersList[i].UserAccount;
                var Check = row.insertCell(3);
                if(UsersList[i].UserRoot == 0) {
                    Check.innerHTML = "用户";
                }
                else if(UsersList[i].UserRoot == 1){
                    Check.innerHTML = "管理员";
                }

                var OpenNews = row.insertCell(4);
                OpenNews.innerHTML = "<button title='"+UsersList[i].UserAccount+"'>删除</button>";



        }
        // 删除
        var buts = document.getElementsByTagName("button");
        console.log(buts);
        var len_but = buts.length;
        for(var i = 1;i<len_but;i++)
        {
            var but = buts[i];
            but.onclick = function () {
                var account = this.title;
                xmlhttp=new XMLHttpRequest();
                xmlhttp.open("POST","DeleteUserHtml",false);
                xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                xmlhttp.send("account="+account);

                window.location.reload();
            }
        }

    }
</script>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
